# -*- coding: utf-8 -*-

from pickle import NONE
import jenkins


class Jenkins:
    def __init__(self, name=None):
        self.jenkins_url = "http://xx.xx.xx/"
        self.jenkins_user = "admin"
        self.jenkins_pass = "xxx"
        self.token = None
        self.password = None
        self.callback = None

    def jenkins_run(self, job_name, data):
        server = jenkins.Jenkins(
            self.jenkins_url, username=self.jenkins_user, password=self.jenkins_pass)
        server.build_job(job_name, data)
        build_number = server.get_job_info(job_name)['lastBuild']['number']
        result = server.get_build_info(job_name, build_number)['result']
        building = server.get_build_info(job_name, build_number)['building']
        print(result)
        task_id = server.get_job_info(job_name)["nextBuildNumber"]
        self.callback(job_name, task_id, result)

    def ansible_playbook_run(self):
        pass

    def ansible_run(self):
        pass

    def k8s_run(self):
        pass




if __name__ == "__main__":
    t = Jenkins()
    t.jenkins_run()
    
